from django.db import models
from django.contrib.auth.models import AbstractUser

# Create your models here.

class Ouser(AbstractUser):
    link = models.URLField(verbose_name="个人网站",blank=True,null=True,help_text="提示:网址必须填写http或https开头的完整路径")
    avatar = models.ImageField(upload_to="images/avatar/%Y/%m/%d/",verbose_name="用户头像",
                               default="images/avatar/default_avatar.png",max_length=500)

    class Meta:
        verbose_name = "用户"
        verbose_name_plural = verbose_name
        ordering = ["-id"]
        db_table = "accounts_user"

    def __str__(self):
        return self.username


class UserPlan(models.Model):
    plan_status = (
        (0, '未完成'),
        (1, '已完成')
    )
    user = models.ForeignKey('Ouser', related_name='self_user', on_delete=models.CASCADE, verbose_name='创建者')
    attention = models.ManyToManyField('Ouser', related_name='attention_user', blank=True, verbose_name='关注者')
    title = models.CharField(max_length=32, verbose_name='计划标题')
    content = models.TextField(verbose_name='计划内容')
    status = models.PositiveSmallIntegerField(choices=plan_status, verbose_name='任务状态', default=0)
    start_time = models.DateTimeField(default='', verbose_name='开始时间')
    end_time = models.DateTimeField(default='', verbose_name='结束时间')
    add_time = models.DateTimeField(auto_now_add=True, verbose_name="添加时间")

    class Meta:
        db_table = 'ops_users_plan'
        verbose_name = '日程管理'
        verbose_name_plural = verbose_name
        unique_together = ('title', 'user')